package lime.xquery.provider;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.w3c.dom.Element;

public class XmlSorter extends ViewerSorter {

	String name;

	public XmlSorter(String name) {
		this.name = name;
	}

	@Override
	public int compare(Viewer viewer, Object e1, Object e2) {
		Element row1 = (Element) e1;
		Element row2 = (Element) e2;

		Element child1 = (Element) row1.getElementsByTagName(name).item(0);
		Element child2 = (Element) row2.getElementsByTagName(name).item(0);

		return child1.getTextContent().compareTo(child2.getTextContent());
	}
}
